/** 
 * Copyright(C) 2010-2011 <webPrj> LTD. All Rights Reserved.                               
 * Project: webPrj
 * Module ID: <0001>
 * Comments: TODO         
 * JDK version used: <JDK1.6.0_25>                              
 * Author: xiamingxing
 * Create Date：09:31:12
 * Modified By: xiamingxing                              
 * Modified Date: 09:31:12                                  
 * Why & What is modified: <修改原因描述>    
 * Version: V1.0                  
 */
package com.xiamx.platform.core.action.base;

import java.io.StringWriter;
import java.sql.SQLException;

import org.apache.log4j.Logger;

import com.opensymphony.xwork2.ActionSupport;
import com.xiamx.platform.exception.AppException;

public abstract class BaseAction extends ActionSupport {

	private static final long serialVersionUID = -7392694229035565712L;
	
	private static Logger logger = Logger.getLogger(BaseAction.class);

	public BaseAction() {}

	public String execute() throws Exception {
		try {
			return executeAction();
		} catch (AppException e) {
			if(null != e.getException()) {
				StringWriter stackTrace = new StringWriter();
				e.getException().printStackTrace(new java.io.PrintWriter(stackTrace));
				logger.error(e.getClassName()+"  "+e.getMessage()+"  "+e.getModule()+"   "+e.getErrCode());
				logger.error(stackTrace.toString());
			} else {
				logger.error(e.getClassName()+"  "+e.getMessage()+"  "+e.getModule()+"   "+e.getErrCode());
			}
			throw new AppException(e.getErrCode(),e.getClassName(),e.getMessage(),e.getModule(),e.getException());
		} catch (SQLException e) {
			StringWriter stackTrace = new StringWriter();
			e.printStackTrace(new java.io.PrintWriter(stackTrace));
			logger.error(this.getClass().getName()+"  "+e.getMessage()+"  BaseAction  " ,e);
			logger.error(stackTrace.toString());
			throw new AppException(this.getClass().getName(),e.getMessage(),e);
		}
	}
	
	public abstract String executeAction() throws AppException, SQLException;
}

